package com.wy.test.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.wy.entity.User;

public class ListSortDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ListSortDemo test = new ListSortDemo();
		
		test.sortList();

	}

	public void sortList(){
		List<User> list = new ArrayList<User>();
		User user = null;
		for(int i=1000;i>0;i--){
			user = new User();
			user.setId(i);
			user.setUsername("u-"+ i);
			user.setPassword("p-"+ i);
			list.add(user);
		}
		System.out.println("list size--->>"+ list.size());
		System.out.println("********************before sort**********************");
		Date start = new Date();
		System.out.println(start.getTime());
//		SystemOutList(list);
		
		// 章节排序
        Collections.sort(list, new Comparator<User>() {
            public int compare(User link1, User link2) {
                return link1.getId().compareTo(link2.getId());
            }
	    });
		System.out.println("********************after sort**********************");
		Date end = new Date();
		System.out.println(end.getTime());
		System.out.println("排序用时--->>"+ (end.getTime() - start.getTime()));
//		SystemOutList(list);
	}
	
	public void SystemOutList(List<User> list){
		if(list != null && list.size()>0){
			User user = null;
			for(int i=0;i<list.size();i++){
				user = list.get(i);
				System.out.println(user.getId() +","+ user.getUsername());
			}
		}
	}
}
